﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace DemoMvcApplication
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "AdminIndex",
                "Admin",
                new
                {
                    controller = "Admin",
                    action = "Index"
                }
            );

            #region AdminUser

            routes.MapRoute("AdminUser", "AdminUser/List/{page}",
                new
                {
                    controller = "AdminUser",
                    action = "List",
                    page = "0"
                },
                new
                {
                    controller = "AdminUser",
                    page = @"\d+"
                });
            routes.MapRoute("AdminUserAction", "AdminUser/{action}/{username}",
                new
                {
                    controller = "AdminUser",
                    action = "",
                    username = ""
                });

            #endregion

            #region AdminUserRole

            routes.MapRoute("AdminUserRole", "AdminUserRole/List/{page}",
                new
                {
                    controller = "AdminUserRole",
                    action = "List",
                    page = "0"
                },
                new
                {
                    controller = "AdminUserRole",
                    page = @"\d+"
                });
            routes.MapRoute("AdminUserRoleAction", "AdminUserRole/{action}/{rolename}",
                new
                {
                    controller = "AdminUserRole",
                    action = "",
                    rolename = ""
                });

            #endregion

            routes.MapRoute(
                "Default",                      // Route name
                "{controller}/{action}/{id}",   // URL with parameters
                new                             // Parameter defaults
                {
                    controller = "Home",
                    action = "Index",
                    id = ""
                }
            );

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}